/**
 * 微信请求
 * @param {string} url - 请求路径
 * @param {string} method - 请求方式
 * @param {object} data - 请求参数
 * @returns - promise
 */
function request(url, method = "GET", sdata) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: `https://homekeep.sdzhuanbang.com/api${url}`,
      method,
      header: {
        // "Content-Type": "application/json",
        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
      },
      data: sdata,
      success: function (res) {
        resolve(res);
      },
      fail: function (err) {
        reject(err);
      },
      complete: function () {
        console.log("请求已发送！");
      },
    });
  });
}

module.exports = {
  request,
};
